package com.user.service.impl;

import com.user.entity.Role;
import com.user.entity.UserSeucrity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println("用户名: "+username);
        Set<Role> authoritySet = new HashSet<>();
        Role authority = new Role("管理员");
        Role authority2 = new Role("测试");
        Role authority3 = new Role("开发");
        Collections.addAll(authoritySet,authority,authority2,authority3);
        UserSeucrity user = new UserSeucrity(username,bCryptPasswordEncoder.encode("1234"),authoritySet);
        return user;
    }
}
